/**
 * 713. 乘积小于 K 的子数组
 */
public class No713 {
    public int numSubarrayProductLessThanK(int[] nums, int k) {
        if (k <= 1) {
            return 0;
        }
        int left = 0, right = 0;
        int n = nums.length;

        int sum = nums[right];

        int result = 0;

        while (left < n) {
            if (sum < k) {
                result += right - left + 1;
                if (right == n - 1) {
                    break;
                }
                right++;
                sum *= nums[right];
            } else {
                sum /= nums[left];
                left++;
            }

        }
        return result;
    }
}
